package pkg

import (
	"custom-oracledb-exporter/config"
	"database/sql"
	"log"

	_ "github.com/godror/godror"
)

var (
	DB *sql.DB
)

func InitOracleDB() {
	// 连接oracle数据库

	// 打开一个连接
	db, err := sql.Open("godror", config.C.Database.GetDsn())
	if err != nil {
		log.Fatalf("Failed to open database: %v", err.Error())
	}
	// defer DB.Close()

	// 用Ping()方法检查数据库连接是否成功
	err = db.Ping()
	if err != nil {
		log.Fatalf("Failed to ping database: %v", err.Error())
	}

	log.Println("Connected to Oracle DB:", config.C.Database.ServiceName)
	DB = db
}
